package com.cn.yang.controller;

import com.alibaba.fastjson.JSONObject;
import com.cn.yang.bean.Personnel;
import com.cn.yang.service.PersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/personnel")
public class PersonnelController {
    @Autowired
    PersonnelService personnelService;

    @RequestMapping("/selectMyMessage")
    public JSONObject selectMyMessage(HttpSession session) {
        String personnelNumber = (String) session.getAttribute("personnelNumber");
        Personnel personnelBean = personnelService.selectMyMessage(personnelNumber);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("personnelBean",personnelBean);
        return jsonObject;
    }
    @RequestMapping("/updateMessage")
    public JSONObject updateMessage(@RequestBody Personnel personnel) {
        int result = personnelService.updateMessage(personnel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        return jsonObject;
    }
    @RequestMapping("/selectAllPersonnel")
    public JSONObject selectAllPersonnel() {
        List<Personnel> list = personnelService.selectAllPersonnel();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }
    @RequestMapping("/personnelAdd")
    public JSONObject personnelAdd(@RequestBody Personnel personnel) {
        int result = personnelService.personnelAdd(personnel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        return jsonObject;
    }
    @RequestMapping("/nonGroupPersonnel")
    public JSONObject nonGroupPersonnel() {
        List<Personnel> list= personnelService.nonGroupPersonnel();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list",list);
        return jsonObject;
    }
    @RequestMapping("/selectById")
    public JSONObject selectById(@RequestBody List<Personnel> list) {
        List<Personnel> personnelBean= personnelService.selectById(list);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("personnelBean",personnelBean);
        return jsonObject;
    }
}
